package com.lb.activity.rest;

import com.lb.activity.service.StationService;
import com.lb.activity.util.ResultUtil;
import com.lb.activity.vo.StationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author liubin
 */
@RestController
@RequestMapping("station")
@Api(value = "岗位管理")
public class StationController {

    @Autowired
    private StationService stationService;


    @GetMapping("toStation")
    @ApiOperation(value = "跳转到岗位页面")
    public ModelAndView toUser(){
        return new ModelAndView("station/station");
    }

    @GetMapping("toAdd")
    @ApiOperation(value = "跳转到岗位添加页面")
    public ModelAndView toAdd(){
        return new ModelAndView("station/station-add");
    }

    @GetMapping("toUpdate")
    @ApiOperation(value = "跳转到岗位更新页面")
    public ModelAndView toUpdate(Long id){
        StationVo stationVo = stationService.getOneById(id);
        ModelAndView modelAndView = new ModelAndView("station/station-update");
        modelAndView.addObject("stationVo",stationVo);
        return modelAndView;
    }


    @GetMapping("list")
    @ApiOperation(value = "分页查询岗位",notes = "分页查询")
    public ResultUtil list(StationVo stationVo){
        ResultUtil resultUtil =  stationService.list(stationVo);
        return resultUtil;
    }

    @PostMapping("add")
    @ApiOperation(value = "添加岗位")
    public ResultUtil add(StationVo station){
        ResultUtil resultUtil = stationService.add(station);
        return resultUtil;
    }

    @PostMapping("update")
    @ApiOperation(value = "更新岗位")
    public ResultUtil update(StationVo station){
        ResultUtil resultUtil = stationService.update(station);
        return resultUtil;
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除岗位")
    public ResultUtil delete(Long id){
        ResultUtil resultUtil = stationService.delete(id);
        return resultUtil;
    }


    @GetMapping("depts")
    @ApiOperation(value = "选择部门")
    public ModelAndView depts(){
        return new ModelAndView("station/depts");
    }

    @GetMapping("getStations")
    @ApiOperation(value = "获取部门下的岗位",notes = "传递部门ID")
    public ResultUtil getStations(Long deptId){
        ResultUtil resultUtil = stationService.stationsByDeptId(deptId);
        return resultUtil;
    }
}
